package com.linkivr.util;
import java.security.*;
public class BaseMd5 {
	 /** Creates a new instance of BaseMd5 */
    public BaseMd5() {
    }

    public static byte [] GetMd5Sum(byte [] srcData) {
        if (srcData==null)
            return null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(srcData);
            return md.digest(); 
        }
        catch (Exception e) {
            return null;
        }
    }

    public static String  GetMd5SumStr(byte [] srcData) {
        if (srcData==null)
            return null;
        byte[] localMd5Bytes;
        StringBuffer localMd5Str=new StringBuffer(new String(""));
        char ch;
        int nBytes;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(srcData);
            localMd5Bytes=md.digest(); 
        }
        catch (Exception e) {
            return null;
        }
        nBytes=localMd5Bytes.length;
        int nIndex;
        int localByte;
        int localChar;
        for(nIndex=0;nIndex<nBytes;nIndex++)
        {
            localByte=(int)(localMd5Bytes[nIndex]);
            if(localByte<0)
                localByte+=256;
            localChar=((localByte&0xf0)>>4);
            if(localChar<10)
                ch=(char)('0'+localChar);
            else
                ch=(char)('a'-10+localChar);
            localMd5Str.append(ch);
            localChar=localByte&0x0f;
            if(localChar<10)
                ch=(char)('0'+localChar);
            else
                ch=(char)('a'-10+localChar);
            localMd5Str.append(ch);
            
        }
        return localMd5Str.toString();
    }
    

}
